package top.zxybird.yun.serialization.thrift;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;

import top.zxybird.yun.serialization.thrift.model.*;

/**
 * public static final byte STOP = 0;<br>
 * public static final byte VOID = 1;<br>
 * public static final byte BOOL = 2;<br>
 * public static final byte BYTE = 3;<br>
 * public static final byte DOUBLE = 4;<br>
 * public static final byte I16 = 6;<br>
 * public static final byte I32 = 8;<br>
 * public static final byte I64 = 10;<br>
 * public static final byte STRING = 11;<br>
 * public static final byte STRUCT = 12;<br>
 * public static final byte MAP = 13;<br>
 * public static final byte SET = 14;<br>
 * public static final byte LIST = 15;<br>
 * public static final byte ENUM = 16;<br>
 */
public class TypeIdTTypeBiMap {

  private static BiMap<Byte, Class<? extends TType>> map = HashBiMap.create();

  static {
    map.put(TTypeConstant.STOP, TStop.class);
    map.put(TTypeConstant.VOID, TVoid.class);
    map.put(TTypeConstant.BOOL, TBoolean.class);
    map.put(TTypeConstant.BYTE, TByte.class);
    map.put(TTypeConstant.DOUBLE, TDouble.class);
    map.put(TTypeConstant.I16, TShort.class);
    map.put(TTypeConstant.I32, TInt.class);
    map.put(TTypeConstant.I64, TLong.class);
    map.put(TTypeConstant.STRING, TString.class);
    map.put(TTypeConstant.STRUCT, TStruct.class);
    map.put(TTypeConstant.MAP, TMap.class);
    map.put(TTypeConstant.SET, TSet.class);
    map.put(TTypeConstant.LIST, TList.class);
    map.put(TTypeConstant.ENUM, TEnum.class);
  }

  public static Class<? extends TType> getByTypeId(Byte type) {
    return map.get(type);
  }

  public static Byte getByTType(Class<? extends TType> clazz) {
    return map.inverse().get(clazz);
  }

}
